<template>
    <div class="data-info" v-loading="loading">
        <div class="condition">
            <span>平台：</span>
            <el-select class="r10" v-model="params.type" style="width:70px" @on-change="searchBtn">
                <el-option value="all" label="全部"/>
                <el-option value="android" label="安卓"/>
                <el-option value="ios" label="IOS"/>
            </el-select>
            <span>时间：</span>
            <date-picker class="r10" @on-change="dateChange"/>
            <el-button type="primary" @click="publish">发布版本</el-button>
        </div>
        <el-table :data="data">
            <el-table-column label="时间" prop="create_time"/>
            <el-table-column label="平台">
                <template slot-scope="{ row }">
                    <span v-if="row.platform ==1">安卓</span>
                    <span v-else>IOS</span>
                </template>
            </el-table-column>
            <el-table-column label="版本号" prop="version"/>
            <el-table-column label="说明" prop="log"/>
            <el-table-column label="强制更新">
                <template slot-scope="{row}">
                    <span v-if="row.must ==1" class="red">是</span>
                    <span v-else>否</span>
                </template>
            </el-table-column>
            <el-table-column label="链接">
                <a slot-scope="{ row }" @click="download(row)">下载</a>
            </el-table-column>
            <el-table-column label="操作">
                <a slot-scope="{row}" class="red" @click="del(row)">删除</a>
            </el-table-column>
        </el-table>
        <page :total="total" :current.sync="params.page" :size.sync="params.size" @change="search"/>
    </div>
</template>

<script>
    import save from "./components/save";
    import {appVersion, appLists} from "@/api";
    import Page from "@/components/page/index";
    import DatePicker from "@/components/date/picker";

    export default {
        components: {DatePicker, Page},
        data() {
            return {
                column: [
                    {title: '时间', key: 'create_time'},
                    {title: '平台', slot: 'platform'},
                    {title: '版本号', key: 'version'},
                    {title: '说明', key: 'log'},
                    {title: '强制更新', slot: 'must'},
                    {title: '链接', slot: 'url'},
                    {title: '操作', slot: 'act'},
                ]
                , data: []
                , params: {
                    size: 10
                    , page: 1
                    , type: 'all'
                }
                , loading: false
                , total: 0
            }
        }
        , mounted() {
            this.search()
        }
        , methods: {
            search() {
                this.loading = true;
                appLists(this.params, (res) => {
                    this.data = res.lists;
                    this.total = parseInt(res.total);
                    this.loading = false;
                }, () => {
                    this.loading = false;
                })
            }
            , searchBtn() {
                this.params.page = 1;
                this.search();
            }
            , del(obj) {
                this.$confirm('确认删除该版本？', () => {
                    this.loading = true;
                    appVersion('delete', {id: obj.id}, () => {
                        this.search();
                    }, () => {
                        this.loading = false;
                    })
                })
            }
            , publish() {
                this.$drawer({
                    title: '发布版本',
                    component: save,
                    data: null,
                    close: this.search,
                })
            }
            , download(obj) {
                window.open(obj.url);
            }
            , dateChange(date) {
                if (date[0]) {
                    this.params.time = date[0] + ',' + date[1];
                } else {
                    this.params.time = '';
                }
                this.searchBtn();
            }
        }
    }
</script>

<style scoped>

</style>
